package com.view.purchasemanage;

import com.bean.Goods;
import com.bean.Purchase;
import com.bean.PurchaseInfo;
import com.bean.Stock;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoTable;
import com.lovo.netCRM.component.LovoTxt;
import com.service.PurchaseService;
import com.service.StockService;
import com.service.impl.PurchaseServiceImpl;
import com.service.impl.StockServiceImpl;
import com.view.MainFrame;
import com.view.inventtorymanage.StockShowDialog;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class PurchaseInfoDialog extends JDialog {

    private LovoButton cancelBtn;
    private JLabel nameTxt,directorTxt,telTxt;
    private LovoTable purchaseInfoTab;


    private MainFrame frame ;
    private int key;
    private Purchase purchase;;

    private PurchaseService purchaseService = new PurchaseServiceImpl();

    public PurchaseInfoDialog(MainFrame frame,int key) {
        // TODO Auto-generated constructor stub
        super(frame,"商品详情",true);
        this.frame = frame;
        this.key = key;
        this.purchase = purchaseInit(key);
        this.setBounds(350, 250, 520, 400);
        this.setLayout(null);
        this.purchase = purchaseInit(key);
        tableInit();
        this.init();
        this.setVisible(true);

    }

    private void tableInit(){
        purchaseInfoTab = new LovoTable(this,
                new String[]{"商品名","厂家","建议采购价","建议销售价","采购数量"},
                new String[]{"goods.name","goods.manufactor","goods.buyPrice","goods.sellPrice","number"},
                "id");
        List<PurchaseInfo> list = new ArrayList<>();
        list = purchaseService.getSelectGoods(purchase);
        purchaseInfoTab.updateLovoTable(list);
        purchaseInfoTab.setSizeAndLocation(20,110,400,200);
    }

    private Purchase purchaseInit(int key){
        Purchase purchase = new Purchase();
        purchase = purchaseService.getSelectPurchase(key);
        return purchase;
    }

    private void init() {
        // TODO Auto-generated method stub

        nameTxt = new JLabel();
        nameTxt.setBounds(20,20,150,60);
        nameTxt.setText("<html>供应商名称："+purchase.getSupplier().getName()+" </html>");
        this.add(nameTxt);

        directorTxt = new JLabel();
        directorTxt.setBounds(20,50,150,60);
        directorTxt.setText("<html>采购员："+purchase.getUser().getRealName()+" </html>");
        this.add(directorTxt);

        telTxt = new JLabel();
        telTxt.setBounds(250,20,150,60);
        telTxt.setText("<html>采购时间："+purchase.getPurchaseDate()+" </html>");
        this.add(telTxt);

        this.cancelBtn = new LovoButton("退出", 270, 320, this);

        cancelBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                PurchaseInfoDialog.this.dispose();;
            }
        });

    }

}
